package com.cdtu.outtake.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtu.outtake.dao.ProductMapper;
import com.cdtu.outtake.domain.Product;
import com.cdtu.outtake.domain.Shop;
import com.cdtu.outtake.service.IProductService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author : shl
 * @Date 2024/1/13 23:36
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>
        implements IProductService {

    /**
     * 根据分类id获取对应菜品
     * @param categoryId
     * @return
     */
    @Override
    public List<Product> getProductsByCategoryId(Long categoryId) {
        return this.baseMapper.selectList(new QueryWrapper<Product>().eq("category_id", categoryId));
    }

    /**
     * 获取菜品
     * @param productId
     * @return
     */
    @Override
    public Product getProductById(Long productId) {
        return baseMapper.selectById(productId);
    }

    @Override
    public List<Shop> getShopBySchoolIdAndKeyword(Long schoolId, String keyword) {
        if (schoolId != null) {
            return this.baseMapper.getShopBySchoolIdAndKeyword(schoolId, keyword);
        } else {
            return this.baseMapper.getShopByKeyword(keyword);
        }
    }
}
